#include<iostream>
#include<stdlib.h>
#include<string>
#include<map>
using namespace std;
map<string,string> change;
map<string,int> group;
int G;

bool process()
{
	string s,mark,tel,day,month,year,time;
	int state1,pos,pos1,pos2,pos3,pos4,g;
	if (!getline(cin,s)) return false;
	while (1)
	{
		getline(cin,s);
		if (s.substr(0,14) == "X-MESSAGE-TYPE") break;
	}
	pos = s.find(':');
	mark = s.substr(pos+1,1000);
	state1 = (mark == "DELIVER");
	while (1)
	{
		getline(cin,s);
		if (s.substr(0,3) == "TEL") break;
	}
	pos = s.find(':');
	tel = s.substr(pos+1,1000);
	while (1)
	{
		getline(cin,s);
		if (s.substr(0,4) == "Date") break;
	}
	pos = s.find(':');
	pos1 = s.find(' ',pos);
	day = s.substr(pos+1,pos1-pos-1);
	pos2 = s.find(' ',pos1+1);
	month = s.substr(pos1+1,pos2-pos1-1);
	month = change[month];
	pos3 = s.find(' ',pos2+1);
	year = s.substr(pos2+1,pos3-pos2-1);
	pos4 = s.find(' ',pos3+1);
	time = s.substr(pos3+1,pos4-pos3-1);
	if (group.count(tel)) g = group[tel];
	else
	{
		G++;
		g = G;
		group[tel] = G;
	}
	if (state1) cout<<"sms,deliver,"<<tel<<",,,"<<year<<'.'<<month<<'.'<<day<<" "<<time<<","<<g<<",";
	else cout<<"sms,submit,,"<<tel<<",,"<<year<<'.'<<month<<'.'<<day<<" "<<time<<","<<g<<",";
	cout<<"\"";
	while (1)
	{
		getline(cin,s);
		if (s == "END:VBODY") break;
		cout<<s;
	}
	cout<<"\""<<endl;
	while (1)
	{
		getline(cin,s);
		if (s.substr(0,8) == "END:VMSG") break;
	}
	return true;
}

void init()
{
	change["Jun"] = "1";
	change["Feb"] = "2";
	change["Mar"] = "3";
	change["Apr"] = "4";
	change["May"] = "5";
	change["Jun"] = "6";
	change["Jul"] = "7";
	change["Aug"] = "8";
	change["Sep"] = "9";
	change["Oct"] = "10";
	change["Nov"] = "11";
	change["Dec"] = "12";
	G = 0;
}

int main()
{
	cout<<endl;
	init();
	while (process());
	return 0;
}
